import type { ComponentPublicInstance, VNodeProps } from "vue";

/**
 * 与MarkdownExtendTagParser搭配使用的自定义组件配置类
 */
export class ComponentConfig {
  instance: ComponentPublicInstance
  props: VNodeProps & Record<string, any>

  constructor(instance: ComponentPublicInstance, props: VNodeProps & Record<string, any>) {
    this.instance = instance
    this.props = props
  }

  getProps(data: object): VNodeProps & Record<string, any> {
    if ('string' === typeof this.props) {
      const result: Record<string, any> = {}
      result[this.props] = data;
      return result;
    } else {
      return { ...this.props, ...data }
    }
  }
}